local nya__duanchang = fk.CreateSkill {

  name = "nya__duanchang",

  tags = { Skill.Compulsory, },

}



nya__duanchang:addEffect(fk.Death, {
  name = "nya__duanchang",
  anim_type = "control",
  frequency = Skill.Compulsory,
  events = {fk.Death, fk.EnterDying},
  can_trigger = function(self, event, target, player, data)
    if target == player and data.damage and data.damage.from and not data.damage.from.dead then
      if event == fk.Death then
        return player:hasSkill(self, false, true)
      else
        return player:hasSkill(nya__duanchang.name) and not player:hasSkill("nya__play", true) and not data.damage.from:isNude()
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = data.damage.from
    if event == fk.Death then
      local skills = {}
      for _, s in ipairs(to.player_skills) do
        if not (s.attached_equip or s.name[#s.name] == "&") then
          table.insertIfNeed(skills, s.name)
        end
      end
      if room.settings.gameMode == "m_1v2_mode" and to.role == "lord" then
        table.removeOne(skills, "m_feiyang")
        table.removeOne(skills, "m_bahu")
      end
      if #skills > 0 then
        room:handleAddLoseSkills(to, "-"..table.concat(skills, "|-"), nil, true, false)
      end
    else
      room:doIndicate(player.id, {to.id})
      if #to:getCardIds("he") < 3 then
        to:throwAllCards("he")
      else
        room:askForDiscard(to, 2, 2, true, nya__duanchang.name, false, ".")
      end
    end
  end,
})
nya__duanchang:addEffect(fk.EnterDying, {
  name = "nya__duanchang",
  anim_type = "control",
  frequency = Skill.Compulsory,
  events = {fk.Death, fk.EnterDying},
  can_trigger = function(self, event, target, player, data)
    if target == player and data.damage and data.damage.from and not data.damage.from.dead then
      if event == fk.Death then
        return player:hasSkill(self, false, true)
      else
        return player:hasSkill(nya__duanchang.name) and not player:hasSkill("nya__play", true) and not data.damage.from:isNude()
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = data.damage.from
    if event == fk.Death then
      local skills = {}
      for _, s in ipairs(to.player_skills) do
        if not (s.attached_equip or s.name[#s.name] == "&") then
          table.insertIfNeed(skills, s.name)
        end
      end
      if room.settings.gameMode == "m_1v2_mode" and to.role == "lord" then
        table.removeOne(skills, "m_feiyang")
        table.removeOne(skills, "m_bahu")
      end
      if #skills > 0 then
        room:handleAddLoseSkills(to, "-"..table.concat(skills, "|-"), nil, true, false)
      end
    else
      room:doIndicate(player.id, {to.id})
      if #to:getCardIds("he") < 3 then
        to:throwAllCards("he")
      else
        room:askForDiscard(to, 2, 2, true, nya__duanchang.name, false, ".")
      end
    end
  end,
})

return nya__duanchang